home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / SUB_ARCT / INPUT / WORK_AGE.JAV < prev    next >
Encoding:
Text File  |  1996-10-04  |  2.8 KB  |  93 lines

  1. package sub_arctic.input;
  2. import sub_arctic.lib.interactor;
  3. import sub_arctic.lib.sub_arctic_error;
  4.  
  5. /**
  6.  * This is the class that handles dispatching the work_procs on
  7.  * the "synchronized side of the world."<P>
  8.  * 
  9.  * User's should never use this class directly but should use
  10.  * the API in the manager instead.
  11.  *
  12.  * @author Ian Smith
  13.  */
  14. public class work_agent extends dispatch_agent {
  15.  
  16.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  17.  
  18.   /**
  19.    * We derive our event code in the same way the animation agent
  20.    * does, by guessing! See the animation_agent code for more
  21.    * on why this is...
  22.    */
  23.   public static final int WORK_EVENT = 1000 + 11;
  24.  
  25.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  26.  
  27.   /** 
  28.    * Indicate whether the given event might be dispatchable by this 
  29.    * agent.  Events will not be delivered to the agent unless they pass this
  30.    * test.   We only accept the work event.
  31.    * 
  32.    * @param event evt the event to be tested for usefulness.
  33.    * @return boolean true if the event is one this agent is interested in.
  34.    */
  35.   public boolean event_is_useful(event evt) {
  36.     return (evt.id()==WORK_EVENT);
  37.   }
  38.  
  39.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  40.  
  41.   /**
  42.    * Dispatch a work event.
  43.    *
  44.    * @param event      evt       the event to dispatch.
  45.    * @param Object     user_info policy defined user information
  46.    * @param interactor to_obj    the object to (possibly)send the event to
  47.    * @param int        seq_num   the sequence number of this event
  48.    */
  49.   public boolean dispatch_event(event evt, Object user_info, 
  50.                 interactor to_obj, int seq_num) {
  51.     Object arg;
  52.     work_pair pair;
  53.     work_proc proc;
  54.  
  55.     /* extract what the manager gave us */
  56.     arg=evt.arg();
  57.     if (arg instanceof work_pair == false) {
  58.       throw new sub_arctic_error("work_agent: Serious problem: unknown "+
  59.                  "argument type inside a work event!"); 
  60.     }
  61.  
  62.     /* extract the prog and the arg */
  63.     pair = (work_pair) arg;
  64.     proc = pair.proc();
  65.     arg=pair.obj();
  66.  
  67.     /* dispatch the closure */
  68.     proc.run_safely(arg);
  69.  
  70.     /* we are done! */
  71.     return true;
  72.   }
  73.  
  74.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  75.  
  76. }
  77. /*=========================== COPYRIGHT NOTICE ===========================
  78.  
  79. This file is part of the subArctic user interface toolkit.
  80.  
  81. Copyright (c) 1996 Scott Hudson and Ian Smith
  82. All rights reserved.
  83.  
  84. The subArctic system is freely available for most uses under the terms
  85. and conditions described in 
  86.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  87. and appearing in full in the lib/interactor.java source file.
  88.  
  89. The current release and additional information about this software can be 
  90. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  91.  
  92. ========================================================================*/
  93.